package cn.itcast.service;

import cn.itcast.dao.CustomerDao;
import cn.itcast.dao.MybatisCustomerDaoImpl;
import cn.itcast.dao.PreparedStatementCustomerDaoImpl;
import cn.itcast.dao.StatementCustomerDaoImpl;
import cn.itcast.dao.ApacheDBUtilsCustomerDaoImpl;
import cn.itcast.dao.CallStatementCustomerDaoImpl;
import cn.itcast.utils.DBType;
import cn.itcast.utils.UUIDUtil;
import cn.itcast.vo.Customer;
import cn.itcast.vo.PageBean;
import java.util.List;

public class CustomerService
{
	
	private CustomerDao getDao() {
	    if (DBType.curDB.equals(DBType.APACHE_DBUTILS)) {
	    	return new ApacheDBUtilsCustomerDaoImpl();
	    } else if (DBType.curDB.equals(DBType.PREPARED_STATEMENT)) {
	    	return new PreparedStatementCustomerDaoImpl();
	    } else if (DBType.curDB.equals(DBType.STATEMENT)) {
	    	return new StatementCustomerDaoImpl();
	    } else if (DBType.curDB.equals(DBType.MYBATIS)) {
	    	return new MybatisCustomerDaoImpl();
	    } else if (DBType.curDB.equals(DBType.CALL_STATEMENT)) {
	    	return new CallStatementCustomerDaoImpl();
	    }
	    return null;
	}
	
  public int save(Customer c)
  {
    String id = UUIDUtil.getUUID();
    
    c.setId(id);
    
    CustomerDao dao = getDao();
    
    return dao.save(c);
  }
  
  public List<Customer> findAll()
  {
    CustomerDao dao = getDao();
    return dao.findAll();
  }
  
  public int delete(String id)
  {
	  CustomerDao dao = getDao();
    return dao.delete(id);
  }
  
  public Customer findById(String id)
  {
	  CustomerDao dao = getDao();
    return dao.findById(id);
  }
  
  public int update(Customer c)
  {
	  CustomerDao dao = getDao();
    return dao.update(c);
  }
  
  public List<Customer> findByWhere(String username, String type)
  {
	  CustomerDao dao = getDao();
    return dao.findByWhere(username, type);
  }
  
  public PageBean<Customer> findByPage(int pageCode, int pageSize)
  {
	  CustomerDao dao = getDao();
    return dao.findByPage(pageCode, pageSize);
  }
}
